Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the deprecation warning of stdext::checked_array_iterator #1769

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

frederick-vs-ja
Copy link

@frederick-vs-ja frederick-vs-ja commented Sep 20, 2023

By adding a non-deprecated copy of checked_array_iterator.

The implementation heavily relies on the implementation details of MSVC STL, but IMO this is OK since we only use it when defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0.

Fixes #1768.

@robert-andrzejuk
Copy link
Contributor

robert-andrzejuk commented Nov 24, 2023

This should use std::span.

@lederernc
Copy link

This should use std::span.

It looks like the rest of the code base is targeting something much older than C++20.

I think this is fine as is.

@kobykahane
Copy link

@barcharcraz Can you review this?

Copy link

@lederernc lederernc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been testing this internally in a conan recipe applying this patch and it works for us.

@pochtmeister
Copy link

Is it possible to merge this into main?

@lederernc
Copy link

lederernc commented Jan 18, 2025

I recently had to address this when some of our devs upgraded to MSVC 17.12.x and this solution was no longer a workable solution for us.

The solution I ended up deploying with patch files in conan for our team were to modify containerstream.h, producerconsumerstream.h and rawptrstream.h as per this patch file:

diff --git a/Release/include/cpprest/containerstream.h b/Release/include/cpprest/containerstream.h
index 6e949a75..cebd01e6 100644
--- a/Release/include/cpprest/containerstream.h
+++ b/Release/include/cpprest/containerstream.h
@@ -399,7 +399,7 @@ private:
         auto readBegin = std::begin(m_data) + m_current_position;
         auto readEnd = std::begin(m_data) + newPos;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
         // Avoid warning C4996: Use checked iterators under SECURE_SCL
         std::copy(readBegin, readEnd, stdext::checked_array_iterator<_CharType*>(ptr, count));
 #else
diff --git a/Release/include/cpprest/producerconsumerstream.h b/Release/include/cpprest/producerconsumerstream.h
index 3487c460..fc1f2e74 100644
--- a/Release/include/cpprest/producerconsumerstream.h
+++ b/Release/include/cpprest/producerconsumerstream.h
@@ -439,7 +439,7 @@ private:
             _CharType* beg = rbegin();
             _CharType* end = rbegin() + countRead;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
             // Avoid warning C4996: Use checked iterators under SECURE_SCL
             std::copy(beg, end, stdext::checked_array_iterator<_CharType*>(dest, count));
 #else
@@ -462,7 +462,7 @@ private:
 
             const _CharType* srcEnd = src + countWritten;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
             // Avoid warning C4996: Use checked iterators under SECURE_SCL
             std::copy(src, srcEnd, stdext::checked_array_iterator<_CharType*>(wbegin(), static_cast<size_t>(avail)));
 #else
diff --git a/Release/include/cpprest/rawptrstream.h b/Release/include/cpprest/rawptrstream.h
index 1f15ecbe..ed2384d4 100644
--- a/Release/include/cpprest/rawptrstream.h
+++ b/Release/include/cpprest/rawptrstream.h
@@ -439,7 +439,7 @@ private:
         auto readBegin = m_data + m_current_position;
         auto readEnd = m_data + newPos;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
         // Avoid warning C4996: Use checked iterators under SECURE_SCL
         std::copy(readBegin, readEnd, stdext::checked_array_iterator<_CharType*>(ptr, count));
 #else
@@ -466,7 +466,7 @@ private:
         if (newSize > m_size) throw std::runtime_error("Writing past the end of the buffer");
 
             // Copy the data
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
         // Avoid warning C4996: Use checked iterators under SECURE_SCL
         std::copy(ptr, ptr + count, stdext::checked_array_iterator<_CharType*>(m_data, m_size, m_current_position));
 #else

@lederernc
Copy link

If it's helpful I can supply an alternate PR with this patch in it. just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stdext::checked_array_iterator compilation error with VS 2022 17.8 Preview 2
5 participants